import { request } from '@/utils/request';

import { PageParams } from './model/pageParams';

/**
 * 订单状态：0-待支付 1-待发货 2-已发货 3-已完成 4-已取消
 */
export interface Order {
  id: number;
  orderNo: string;
  userId: number;
  goodsId: number;
  supplierId: number;
  quantity: number;
  totalAmount: number;
  status: number;
  createTime: string;
  updateTime: string;
}

/**
 * 分页查询
 */
export const page = (params: PageParams) => {
  return request.post({
    url: '/order/page',
    data: params,
  });
};

/**
 * 获取订单详情
 */
export const getOrder = (id: number) => {
  return request.get({
    url: `/goods/page/${id}`,
  });
};

/**
 * 创建订单
 */
export const createOrder = (params: any) => {
  return request.post<boolean>({
    url: '/order/create',
    data: params,
  });
};

/**
 * 取消订单
 */
export const cancelOrder = (id: number) => {
  return request.post<boolean>({
    url: `/order/cancel/${id}`,
  });
};

/**
 * 确认收货
 */
export const confirmReceive = (id: number) => {
  return request.post<boolean>({
    url: `/order/receive/${id}`,
  });
};

/**
 * 发货
 */
export const ship = (id: number) => {
  return request.post<boolean>({
    url: `/order/ship/${id}`,
  });
};
